<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />

    

    
    <title>Java集合之Map | welcome</title>
    
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="keywords" content="Map,HashMap,HashTabel,TreeMap" />
    
    <meta name="description" content="Java集合之Map写下这个也算是复习一下之前学习的知识吧。 Map集合Map集合存储的是 key-value 形式的键值对，需要保证键的唯一性。 接口中定义了一些方法 1、添加 12V put(K key, V value)void putAll(Map&lt;? extends K,? extends V&gt; m)  2、删除 12void clear()     &#x2F;&#x2F;从这个映射中移除所">
<meta property="og:type" content="article">
<meta property="og:title" content="Java集合之Map">
<meta property="og:url" content="https://hchdream.gitee.io/hexo/2020/05/16/Java%E9%9B%86%E5%90%88%E4%B9%8BMap/index.html">
<meta property="og:site_name" content="welcome">
<meta property="og:description" content="Java集合之Map写下这个也算是复习一下之前学习的知识吧。 Map集合Map集合存储的是 key-value 形式的键值对，需要保证键的唯一性。 接口中定义了一些方法 1、添加 12V put(K key, V value)void putAll(Map&lt;? extends K,? extends V&gt; m)  2、删除 12void clear()     &#x2F;&#x2F;从这个映射中移除所">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://hchdream.gitee.io/images/img/portfolio/05-large.jpg">
<meta property="article:published_time" content="2020-05-15T16:00:00.000Z">
<meta property="article:modified_time" content="2020-10-28T08:35:23.205Z">
<meta property="article:author" content="XiaoHuang">
<meta property="article:tag" content="Map">
<meta property="article:tag" content="HashMap">
<meta property="article:tag" content="HashTabel">
<meta property="article:tag" content="TreeMap">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://hchdream.gitee.io/images/img/portfolio/05-large.jpg">
    

    
        <link rel="alternate" href="/atom.xml" title="welcome" type="application/atom+xml" />
    

    
        <link rel="icon" href="/hexo/css/images/favicon.ico" />
    

    
<link rel="stylesheet" href="/hexo/libs/font-awesome/css/font-awesome.min.css">

    
<link rel="stylesheet" href="/hexo/libs/titillium-web/styles.css">

    
<link rel="stylesheet" href="/hexo/libs/source-code-pro/styles.css">


    
<link rel="stylesheet" href="/hexo/css/style.css">


    
<script src="/hexo/libs/jquery/3.5.0/jquery.min.js"></script>

    
    
        
<link rel="stylesheet" href="/hexo/libs/lightgallery/css/lightgallery.min.css">

    
    
        
<link rel="stylesheet" href="/hexo/libs/justified-gallery/justifiedGallery.min.css">

    
    
    
    


<meta name="generator" content="Hexo 5.2.0"></head>

<body>
    <div id="wrap">
        <header id="header">
    <div id="header-outer" class="outer">
        <div class="container">
            <div class="container-inner">
                <div id="header-title">
                    <h1 class="logo-wrap">
                        <a href="/hexo/" class="logo"></a>
                    </h1>
                    
                </div>
                <div id="header-inner" class="nav-container">
                    <a id="main-nav-toggle" class="nav-icon fa fa-bars"></a>
                    <div class="nav-container-inner">
                        <ul id="main-nav">
                            
                                <li class="main-nav-list-item" >
                                    <a class="main-nav-list-link" href="/hexo/">主页</a>
                                </li>
                            
                                    <ul class="main-nav-list"><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/Java/">Java</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/Spring/">Spring</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/nginx/">nginx</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/springcloud/">springcloud</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F/">镜像加速</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/hexo/categories/%E9%A1%B9%E7%9B%AE/">项目</a></li></ul>
                                
                                <li class="main-nav-list-item" >
                                    <a class="main-nav-list-link" href="/hexo/about/index.html">关于</a>
                                </li>
                            
                        </ul>
                        <nav id="sub-nav">
                            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/hexo/',
        CONTENT_URL: '/hexo/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/hexo/js/insight.js"></script>


</div>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>

        <div class="container">
            <div class="main-body container-inner">
                <div class="main-body-inner">
                    <section id="main">
                        <div class="main-body-header">
    <h1 class="header">
    
    <a class="page-title-link" href="/hexo/categories/Java/">Java</a>
    </h1>
</div>

                        <div class="main-body-content">
                            <article id="post-Java集合之Map" class="article article-single article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
        Java集合之Map
        </h1>
    

            </header>
        
        
            <div class="article-meta">
                
  <div class="article-date">
    <i class="fa fa-calendar"></i>
    <a href="/hexo/2020/05/16/Java%E9%9B%86%E5%90%88%E4%B9%8BMap/" class="article-date">
       <time datetime="2020-05-15T16:00:00.000Z" itemprop="datePublished">2020-05-16</time>
    </a>
  </div>


<div class="article-date">
  <i class="fa fa-calendar-plus-o"></i>
  <a href="/hexo/2020/05/16/Java%E9%9B%86%E5%90%88%E4%B9%8BMap/" class="article-date">
     <time datetime="2020-10-28T08:35:23.205Z" itemprop="dateModified">2020-10-28</time>
  </a>
</div>


                

                
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link-link" href="/hexo/tags/HashMap/" rel="tag">HashMap</a>, <a class="tag-link-link" href="/hexo/tags/HashTabel/" rel="tag">HashTabel</a>, <a class="tag-link-link" href="/hexo/tags/Map/" rel="tag">Map</a>, <a class="tag-link-link" href="/hexo/tags/TreeMap/" rel="tag">TreeMap</a>
    </div>

                

                

            </div>
        
        
        <div class="article-entry" itemprop="articleBody">
            

            

            

            <p><img src="https://hchdream.gitee.io/images/img/portfolio/05-large.jpg"></p>
<h1 id="Java集合之Map"><a href="#Java集合之Map" class="headerlink" title="Java集合之Map"></a>Java集合之Map</h1><p>写下这个也算是复习一下之前学习的知识吧。</p>
<h2 id="Map集合"><a href="#Map集合" class="headerlink" title="Map集合"></a>Map集合</h2><p>Map集合存储的是 key-value 形式的键值对，需要保证键的唯一性。</p>
<p>接口中定义了一些方法</p>
<p>1、添加</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">V <span class="title">put</span><span class="params">(K key, V value)</span></span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">putAll</span><span class="params">(Map&lt;? extends K,? extends V&gt; m)</span></span></span><br></pre></td></tr></table></figure>

<p>2、删除</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">clear</span><span class="params">()</span>     <span class="comment">//从这个映射中移除所有的映射</span></span></span><br><span class="line"><span class="function">V <span class="title">remove</span><span class="params">(Object key)</span>	<span class="comment">//通过键移除对应的键值对 </span></span></span><br></pre></td></tr></table></figure>

<p>3、判断</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">boolean</span>  <span class="title">containsKey</span><span class="params">(Object key)</span>	<span class="comment">//判断是否存在指定键值的键值对，返回值为布尔型</span></span></span><br><span class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">containsValue</span><span class="params">(Object value)</span>	<span class="comment">//判断是否存在指定value的键值对</span></span></span><br><span class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">isEmpty</span><span class="params">()</span>		<span class="comment">//判断集合是否为空</span></span></span><br></pre></td></tr></table></figure>

<p>4、获取</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">V <span class="title">get</span><span class="params">(Object key)</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">size</span><span class="params">()</span>  <span class="comment">//返回这个映射中的键值映射的数目</span></span></span><br><span class="line"><span class="function">Collection&lt;V&gt; <span class="title">values</span><span class="params">()</span>  <span class="comment">//返回一个 Collection视图的值包含在这个Map</span></span></span><br></pre></td></tr></table></figure>

<p>Map接口有三个常用的实现类</p>
<ul>
<li>HashMap:底层是哈希表数据结构，允许使用null键null值，线程非同步，效率高(jdk 1.2)</li>
<li>HashTable:底层是哈希表数据结构，哈希表映射了键的值，不能存入null键或null值，线程同步，效率相对低</li>
<li>TreeMap:底层是二叉树数据结构，线程非同步，可以用于给Map集合中的键排序，和Collection的Set相似，实际上Set底层就是使用了Map集合</li>
</ul>
<h3 id="HashMap"><a href="#HashMap" class="headerlink" title="HashMap"></a>HashMap</h3><p>一个简单HashMap的Demo</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Collection;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MapDemo</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Map&lt;String, String&gt; map = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        <span class="comment">//添加元素，相同的键对应的值会被后添加的元素的值覆盖掉，并且返回之前对应的值</span></span><br><span class="line">        System.out.println(<span class="string">&quot;put():&quot;</span>+map.put(<span class="string">&quot;66&quot;</span>,<span class="string">&quot;xixi&quot;</span>));</span><br><span class="line">        System.out.println(<span class="string">&quot;put():&quot;</span>+map.put(<span class="string">&quot;66&quot;</span>,<span class="string">&quot;huanhuan&quot;</span>));</span><br><span class="line">        map.put(<span class="string">&quot;01&quot;</span>, <span class="string">&quot;zhangsan1&quot;</span>);</span><br><span class="line">        map.put(<span class="string">&quot;02&quot;</span>, <span class="string">&quot;zhangsan2&quot;</span>);</span><br><span class="line">        map.put(<span class="string">&quot;03&quot;</span>, <span class="string">&quot;zhangsan3&quot;</span>);</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">&quot;containsKey():&quot;</span> + map.containsKey(<span class="string">&quot;02&quot;</span>));</span><br><span class="line">        System.out.println(<span class="string">&quot;remove():&quot;</span> + map.remove(<span class="string">&quot;022&quot;</span>));<span class="comment">//不存在返回null</span></span><br><span class="line">        System.out.println(<span class="string">&quot;remove():&quot;</span> + map.remove(<span class="string">&quot;02&quot;</span>));<span class="comment">//返回对应的Value</span></span><br><span class="line">        System.out.println(<span class="string">&quot;get():&quot;</span>+map.get(<span class="string">&quot;01&quot;</span>));</span><br><span class="line">        System.out.println(<span class="string">&quot;get():&quot;</span>+map.get(<span class="string">&quot;012&quot;</span>));<span class="comment">//不存在返回null</span></span><br><span class="line">        map.put(<span class="keyword">null</span>,<span class="string">&quot;kongxin&quot;</span>);<span class="comment">//HashMap允许以null作为键和值,但是键只能有一个为null</span></span><br><span class="line">        map.put(<span class="string">&quot;04&quot;</span>,<span class="keyword">null</span>);</span><br><span class="line">        System.out.println(<span class="string">&quot;get():&quot;</span>+map.get(<span class="keyword">null</span>));</span><br><span class="line">        System.out.println(<span class="string">&quot;get():&quot;</span>+map.get(<span class="string">&quot;04&quot;</span>));</span><br><span class="line">        System.out.println(map);</span><br><span class="line">        Collection&lt;String&gt; values = map.values();</span><br><span class="line">        System.out.println(values);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>输出结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">put():null</span><br><span class="line">put():xixi</span><br><span class="line">containsKey():true</span><br><span class="line">remove():null</span><br><span class="line">remove():zhangsan2</span><br><span class="line">get():zhangsan1</span><br><span class="line">get():null</span><br><span class="line">get():kongxin</span><br><span class="line">get():null</span><br><span class="line">&#123;66&#x3D;huanhuan, null&#x3D;kongxin, 01&#x3D;zhangsan1, 03&#x3D;zhangsan3, 04&#x3D;null&#125;</span><br><span class="line">[huanhuan, kongxin, zhangsan1, zhangsan3, null]</span><br></pre></td></tr></table></figure>

<p>Map集合有两种取出方式</p>
<p>1、Set<K> keySet()：将Map中所有的键存入到Set集合，Set集合有迭代器，所有可以用迭代的方式取出所有键，再根据get方法获取每一个键对应的值，Map集合的取值原理：将Map集合转成Set集合，通过Set集合的迭代器取出。</K></p>
<p>2、Set&lt;Map.Entry&lt;K,V&gt;&gt; entrySet()：将Map集合中的映射关系存入到了Set集合中，而这个关系的数据类型就是Map.Entry</p>
<p>下面是代码的示例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Iterator;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Map集合的两种取出方式</span></span><br><span class="line"><span class="comment"> * 1、Set&lt;K&gt; keySet()：将Map中所有的键存入到Set集合，Set集合有迭代器，所有可以用迭代的方式取出所有键，再根据get方法获取每一个键对应的值</span></span><br><span class="line"><span class="comment"> * Map集合的取值原理：将Map集合转成Set集合，通过Set集合的迭代器取出。</span></span><br><span class="line"><span class="comment"> * 2、Set&lt;Map.Entry&lt;K,V&gt;&gt; entrySet()：将Map集合中的映射关系存入到了Set集合中，而这个关系的数据类型就是Map.Entry</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MapDemo2</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Map&lt;String, String&gt; map = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        map.put(<span class="string">&quot;001&quot;</span>, <span class="string">&quot;zhangsan1&quot;</span>);</span><br><span class="line">        map.put(<span class="string">&quot;002&quot;</span>, <span class="string">&quot;zhangsan2&quot;</span>);</span><br><span class="line">        map.put(<span class="string">&quot;003&quot;</span>, <span class="string">&quot;zhangsan3&quot;</span>);</span><br><span class="line">        map.put(<span class="string">&quot;004&quot;</span>, <span class="string">&quot;zhangsan4&quot;</span>);</span><br><span class="line">        <span class="comment">//将Map集合中的映射关系取出,存入到Set集合中</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * Map.Entry 其实Entry也是一个接口，它是Map接口中的一个内部接口</span></span><br><span class="line"><span class="comment">         * public static interface Map.Entry&lt;K,V&gt;</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        Set&lt;Map.Entry&lt;String, String&gt;&gt; entries = map.entrySet();</span><br><span class="line">        Iterator&lt;Map.Entry&lt;String, String&gt;&gt; iterator = entries.iterator();</span><br><span class="line">        <span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">            Map.Entry&lt;String, String&gt; entry = iterator.next();</span><br><span class="line">            String key = entry.getKey();</span><br><span class="line">            String value = entry.getValue();</span><br><span class="line">            System.out.println(key + <span class="string">&quot;=&quot;</span> + value);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//先获取map集合所有的键的Set集合,keySet</span></span><br><span class="line">        <span class="comment">/*Set&lt;String&gt; keys = map.keySet();</span></span><br><span class="line"><span class="comment">        //有了Set集合就可以获取其迭代器</span></span><br><span class="line"><span class="comment">        Iterator&lt;String&gt; iterator = keys.iterator();</span></span><br><span class="line"><span class="comment">        while (iterator.hasNext()) &#123;</span></span><br><span class="line"><span class="comment">            String key = iterator.next();</span></span><br><span class="line"><span class="comment">            //有了键可以通过map集合的get方法获取其对应的值</span></span><br><span class="line"><span class="comment">            String value = map.get(key);</span></span><br><span class="line"><span class="comment">            System.out.println(key + &quot;=&quot; + value);</span></span><br><span class="line"><span class="comment">        &#125;*/</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">001&#x3D;zhangsan1</span><br><span class="line">002&#x3D;zhangsan2</span><br><span class="line">003&#x3D;zhangsan3</span><br><span class="line">004&#x3D;zhangsan4</span><br></pre></td></tr></table></figure>

<p>这两种方式个人更喜欢第二种，这种取出元素的方式虽然比较繁琐，但是优点在于实际开发中，想要对取出的元素进行操作，会很方便，还有一种增强for循环的形式也可以取出Map中的元素，虽然代码十分简洁，但是却很难对键值对进行操作，各有利弊。</p>
<h3 id="TreeMap"><a href="#TreeMap" class="headerlink" title="TreeMap"></a>TreeMap</h3><p>下面是一个练习题</p>
<p>需求，对学生的年龄进行升序排序</p>
<p>因为数据是以键值对形式存在的</p>
<p>所以要使用可以排序的Map集合，TreeMap</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> Collection.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 需求，对学生的年龄进行升序排序</span></span><br><span class="line"><span class="comment"> * 因为数据是以键值对形式存在的</span></span><br><span class="line"><span class="comment"> * 所以要使用可以排序的Map集合，TreeMap</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MapTest2</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        TreeMap&lt;Student, String&gt; treeMap = <span class="keyword">new</span> TreeMap&lt;&gt;(<span class="keyword">new</span> StuNameComparator());</span><br><span class="line">        treeMap.put(<span class="keyword">new</span> Student(<span class="string">&quot;b张三1&quot;</span>, <span class="number">18</span>), <span class="string">&quot;武汉&quot;</span>);</span><br><span class="line">        treeMap.put(<span class="keyword">new</span> Student(<span class="string">&quot;张三2&quot;</span>, <span class="number">19</span>), <span class="string">&quot;武汉&quot;</span>);</span><br><span class="line">        treeMap.put(<span class="keyword">new</span> Student(<span class="string">&quot;a张三3&quot;</span>, <span class="number">20</span>), <span class="string">&quot;武汉&quot;</span>);</span><br><span class="line">        treeMap.put(<span class="keyword">new</span> Student(<span class="string">&quot;张三4&quot;</span>, <span class="number">21</span>), <span class="string">&quot;武汉&quot;</span>);</span><br><span class="line">        treeMap.put(<span class="keyword">new</span> Student(<span class="string">&quot;王五&quot;</span>, <span class="number">21</span>), <span class="string">&quot;北京&quot;</span>);</span><br><span class="line">        treeMap.put(<span class="keyword">new</span> Student(<span class="string">&quot;王五&quot;</span>, <span class="number">21</span>), <span class="string">&quot;北京&quot;</span>);<span class="comment">//重复元素</span></span><br><span class="line"></span><br><span class="line">        Set&lt;Map.Entry&lt;Student, String&gt;&gt; entrySet = treeMap.entrySet();</span><br><span class="line">        <span class="comment">//获取迭代器</span></span><br><span class="line">        Iterator&lt;Map.Entry&lt;Student, String&gt;&gt; iterator = entrySet.iterator();</span><br><span class="line">        <span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">            Map.Entry&lt;Student, String&gt; map = iterator.next();</span><br><span class="line">            Student student = map.getKey();</span><br><span class="line">            String address = map.getValue();</span><br><span class="line">            System.out.println(<span class="string">&quot;name:&quot;</span> + student.getName() + <span class="string">&quot;,age:&quot;</span> + student.getAge() + <span class="string">&quot;,address:&quot;</span> + address);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>自定义比较器</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Comparator;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 自定义学生的比较器</span></span><br><span class="line"><span class="comment"> * 按姓名进行排序</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">StuNameComparator</span> <span class="keyword">implements</span> <span class="title">Comparator</span>&lt;<span class="title">Student</span>&gt; </span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">compare</span><span class="params">(Student o1, Student o2)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> result = o1.getName().compareTo(o2.getName());</span><br><span class="line">        <span class="keyword">if</span> (result == <span class="number">0</span>)</span><br><span class="line">            <span class="keyword">return</span> o1.getAge().compareTo(o2.getAge());</span><br><span class="line">        <span class="keyword">return</span> result;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">name:a张三<span class="number">3</span>,age:<span class="number">20</span>,address:武汉</span><br><span class="line">name:b张三<span class="number">1</span>,age:<span class="number">18</span>,address:武汉</span><br><span class="line">name:张三<span class="number">2</span>,age:<span class="number">19</span>,address:武汉</span><br><span class="line">name:张三<span class="number">4</span>,age:<span class="number">21</span>,address:武汉</span><br><span class="line">name:王五,age:<span class="number">21</span>,address:北京</span><br></pre></td></tr></table></figure>

<p> 要求：</p>
<p>“abcdab,cde+fabc”获取字符串中字母出现的次数，还要除去字符串中的非字母部分</p>
<p> 希望打印：a(1)b()… * 通过结果发现，美每一个字母都有对应的次数</p>
<p> 说明字母与出现次数之间存在映射关系 * Map集合存放映射关系</p>
<p> 思路：</p>
<p> 1、将字符串转为字符数组，因为要对每一个字母进行操作</p>
<p> 2、定义一个map集合，因为打印结果的字母有顺序，所以使用treeMap集合</p>
<p>  3、遍历字符数组，将每一个字母作为键去查map集合 * 如果返回null，将该字母和1存入到，map集合中 ， 如果返回不是null，说明该字母在map集合内已经存在并有对应次数， 那么就获取该次数并进行自增，然后将该字母和自增后的次数存入到map集合中，覆盖掉原来j键所对应的值</p>
<p>4、将map集合中的数据变成指定的字符串形式返回 </p>
<p>直接上代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Iterator;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"><span class="keyword">import</span> java.util.TreeMap;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &quot;sdasdsafsdjfkjldjkldankvn&quot;获取字符串中字母出现的次数</span></span><br><span class="line"><span class="comment"> * 希望打印：a(1)b()...</span></span><br><span class="line"><span class="comment"> * 通过结果发现，美每一个字母都有对应的次数</span></span><br><span class="line"><span class="comment"> * 说明字母与出现次数之间存在映射关系</span></span><br><span class="line"><span class="comment"> * Map集合存放映射关系</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * 思路：</span></span><br><span class="line"><span class="comment"> * 1、将字符串转为字符数组，因为要对每一个字母进行操作</span></span><br><span class="line"><span class="comment"> * 2、定义一个map集合，因为打印结果的字母有顺序，所以使用treeMap集合</span></span><br><span class="line"><span class="comment"> * 3、遍历字符数组，将每一个字母作为键去查map集合</span></span><br><span class="line"><span class="comment"> * 如果返回null，将该字母和1存入到，map集合中</span></span><br><span class="line"><span class="comment"> * 如果返回不是null，说明该字母在map集合内已经存在并有对应次数</span></span><br><span class="line"><span class="comment"> * 那么就获取该次数并进行自增，然后将该字母和自增后的次数存入到map集合中，覆盖掉原来j键所对应的值</span></span><br><span class="line"><span class="comment"> * 4、将map集合中的数据变成指定的字符串形式返回</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MapTest3</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String str = charCount(<span class="string">&quot;abcdab,cde+fabc&quot;</span>);</span><br><span class="line">        System.out.println(str);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">charCount</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//将字符串转为字符数组</span></span><br><span class="line">        <span class="keyword">char</span>[] chs = str.toCharArray();</span><br><span class="line">        <span class="comment">//统计字母数字的变量</span></span><br><span class="line">        <span class="comment">//int count = 0;</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * public final class Character extends Object implements Serializable, Comparable&lt;Character&gt;</span></span><br><span class="line"><span class="comment">         *     Character默认实现了Comparable接口，自然排序</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        TreeMap&lt;Character, Integer&gt; treeMap = <span class="keyword">new</span> TreeMap&lt;&gt;();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; chs.length; i++) &#123;</span><br><span class="line">            <span class="comment">//如果出现其他特殊字符，要去除</span></span><br><span class="line">            <span class="keyword">if</span> (!(chs[i] &gt;= <span class="string">&#x27;a&#x27;</span> &amp;&amp; chs[i] &lt;= <span class="string">&#x27;z&#x27;</span> || chs[i] &gt;= <span class="string">&#x27;A&#x27;</span> &amp;&amp; chs[i] &lt;= <span class="string">&#x27;Z&#x27;</span>))</span><br><span class="line">                <span class="keyword">continue</span>;<span class="comment">//如果不是字母继续循环，不做后面的操作</span></span><br><span class="line"></span><br><span class="line">            Integer value = treeMap.get(chs[i]);</span><br><span class="line">            <span class="keyword">if</span> (value == <span class="keyword">null</span>)<span class="comment">//不存在该字母</span></span><br><span class="line">            &#123;</span><br><span class="line">                treeMap.put(chs[i], <span class="number">1</span>);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                value = value + <span class="number">1</span>;<span class="comment">//集合中已经有了该字母，个数自增再存入集合</span></span><br><span class="line">                treeMap.put(chs[i], value);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//System.out.println(treeMap);</span></span><br><span class="line">        <span class="comment">//字符串缓冲区</span></span><br><span class="line">        StringBuilder stringBuilder = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">        Set&lt;Map.Entry&lt;Character, Integer&gt;&gt; entrySet = treeMap.entrySet();</span><br><span class="line">        Iterator&lt;Map.Entry&lt;Character, Integer&gt;&gt; iterator = entrySet.iterator();</span><br><span class="line">        <span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">            Map.Entry&lt;Character, Integer&gt; next = iterator.next();</span><br><span class="line">            Character key = next.getKey();</span><br><span class="line">            Integer value = next.getValue();</span><br><span class="line">            stringBuilder.append(key + <span class="string">&quot;(&quot;</span> + value + <span class="string">&quot;)&quot;</span> + <span class="string">&quot; &quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> stringBuilder.toString();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a(3) d(5) f(2) j(3) k(3) l(2) n(2) s(4) v(1) </span><br></pre></td></tr></table></figure>




        </div>
        <footer class="article-footer">
            



    <a data-url="https://hchdream.gitee.io/hexo/2020/05/16/Java%E9%9B%86%E5%90%88%E4%B9%8BMap/" data-id="ckqnkn7if0001s8rj2mv05u2w" class="article-share-link"><i class="fa fa-share"></i>分享到</a>
<script>
    (function ($) {
        $('body').on('click', function() {
            $('.article-share-box.on').removeClass('on');
        }).on('click', '.article-share-link', function(e) {
            e.stopPropagation();

            var $this = $(this),
                url = $this.attr('data-url'),
                encodedUrl = encodeURIComponent(url),
                id = 'article-share-box-' + $this.attr('data-id'),
                offset = $this.offset(),
                box;

            if ($('#' + id).length) {
                box = $('#' + id);

                if (box.hasClass('on')){
                    box.removeClass('on');
                    return;
                }
            } else {
                var html = [
                    '<div id="' + id + '" class="article-share-box">',
                        '<input class="article-share-input" value="' + url + '">',
                        '<div class="article-share-links">',
                            '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
                            '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
                            '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="article-share-pinterest" target="_blank" title="Pinterest"></a>',
                            '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="article-share-google" target="_blank" title="Google+"></a>',
                        '</div>',
                    '</div>'
                ].join('');

              box = $(html);

              $('body').append(box);
            }

            $('.article-share-box.on').hide();

            box.css({
                top: offset.top + 25,
                left: offset.left
            }).addClass('on');

        }).on('click', '.article-share-box', function (e) {
            e.stopPropagation();
        }).on('click', '.article-share-box-input', function () {
            $(this).select();
        }).on('click', '.article-share-box-link', function (e) {
            e.preventDefault();
            e.stopPropagation();

            window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
        });
    })(jQuery);
</script>

        </footer>
    </div>
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "BlogPosting",
        "author": {
            "@type": "Person",
            "name": "XiaoHuang"
        },
        "headline": "Java集合之Map",
        "image": "https://hchdream.gitee.io/hexohttps://hchdream.gitee.io/images/img/portfolio/05-large.jpg",
        "keywords": "Map HashMap HashTabel TreeMap",
        "genre": "Java",
        "datePublished": "2020-05-16",
        "dateCreated": "2020-05-16",
        "dateModified": "2020-10-28",
        "url": "https://hchdream.gitee.io/hexo/2020/05/16/Java集合之Map/",
        "description": "
Java集合之Map写下这个也算是复习一下之前学习的知识吧。
Map集合Map集合存储的是 key-value 形式的键值对，需要保证键的唯一性。
接口中定义了一些方法
1、添加
12V put(K key, V value)void putAll(Map&lt;? extends K,? extends V&gt; m)

2、删除
12void clear()     //从这个映射中移除所",
        "wordCount": 2220
    }
</script>

</article>

    <section id="comments">
    
        
    <div id="disqus_thread">
        <noscript>Please enable JavaScript to view the <a target="_blank" rel="noopener" href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    </div>


    
    </section>



                        </div>
                    </section>
                    <aside id="sidebar">
    <a class="sidebar-toggle" title="Expand Sidebar"><i class="toggle icon"></i></a>
    <div class="sidebar-top">
        <p>关注我 :</p>
        <ul class="social-links">
            
                
                <li>
                    <a class="social-tooltip" title="github" href="https://github.com/hchdream" target="_blank" rel="noopener">
                        <i class="icon fa fa-github"></i>
                    </a>
                </li>
                
            
                
                <li>
                    <a class="social-tooltip" title="rss" href="/hexo/atom.xml" target="_blank" rel="noopener">
                        <i class="icon fa fa-rss"></i>
                    </a>
                </li>
                
            
        </ul>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/hexo/2020/05/28/Spring/" id="article-nav-newer" class="article-nav-link-wrap">
        <strong class="article-nav-caption">下一篇</strong>
        <p class="article-nav-title">
        
            Spring学习笔记
        
        </p>
        <i class="icon fa fa-chevron-right" id="icon-chevron-right"></i>
    </a>
    
    
        <a href="/hexo/2020/05/16/%E5%8D%95%E4%BE%8B%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" id="article-nav-older" class="article-nav-link-wrap">
        <strong class="article-nav-caption">上一篇</strong>
        <p class="article-nav-title">单例设计模式</p>
        <i class="icon fa fa-chevron-left" id="icon-chevron-left"></i>
        </a>
    
</nav>

    
    <div class="widgets-container">
        
            
                

            
                
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="">
                
                    <li>
                        
                        <div class="item-thumbnail">
                            <a href="/hexo/2021/07/03/SpringCloud-Alibaba/" class="thumbnail">
    
    
        <span style="background-image:url(https://w.wallhaven.cc/full/j3/wallhaven-j3wqwm.jpg)" alt="SpringCloud&amp;Alibaba" class="thumbnail-image"></span>
    
    
</a>

                        </div>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/hexo/categories/springcloud/">springcloud</a></p>
                            <p class="item-title"><a href="/hexo/2021/07/03/SpringCloud-Alibaba/" class="title">SpringCloud&amp;Alibaba</a></p>
                            <p class="item-date"><time datetime="2021-07-03T08:26:10.000Z" itemprop="datePublished">2021-07-03</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-thumbnail">
                            <a href="/hexo/2021/01/29/nginx/" class="thumbnail">
    
    
        <span style="background-image:url(http://hchdream.gitee.io/images/img/portfolio/08-large.jpg)" alt="nginx入门" class="thumbnail-image"></span>
    
    
</a>

                        </div>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/hexo/categories/nginx/">nginx</a></p>
                            <p class="item-title"><a href="/hexo/2021/01/29/nginx/" class="title">nginx入门</a></p>
                            <p class="item-date"><time datetime="2021-01-28T16:00:00.000Z" itemprop="datePublished">2021-01-29</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-thumbnail">
                            <a href="/hexo/2020/10/29/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" class="thumbnail">
    
    
        <span style="background-image:url(http://hchdream.gitee.io/images/img/portfolio/10-large.jpg)" alt="网络编程" class="thumbnail-image"></span>
    
    
</a>

                        </div>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/hexo/categories/Java/">Java</a></p>
                            <p class="item-title"><a href="/hexo/2020/10/29/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" class="title">网络编程</a></p>
                            <p class="item-date"><time datetime="2020-10-29T05:39:12.000Z" itemprop="datePublished">2020-10-29</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-thumbnail">
                            <a href="/hexo/2020/10/27/%E6%B5%8B%E8%AF%95/" class="thumbnail">
    
    
        <span style="background-image:url(https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2926199504,3558053336&fm=26&gp=0.jpg)" alt="测试" class="thumbnail-image"></span>
    
    
</a>

                        </div>
                        
                        <div class="item-inner">
                            <p class="item-category"></p>
                            <p class="item-title"><a href="/hexo/2020/10/27/%E6%B5%8B%E8%AF%95/" class="title">测试</a></p>
                            <p class="item-date"><time datetime="2020-10-27T08:16:08.000Z" itemprop="datePublished">2020-10-27</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-thumbnail">
                            <a href="/hexo/2020/10/27/hello-world/" class="thumbnail">
    
    
        <span style="background-image:url(https://hchdream.gitee.io/images/img/portfolio/04-large.jpg)" alt="Hello World" class="thumbnail-image"></span>
    
    
</a>

                        </div>
                        
                        <div class="item-inner">
                            <p class="item-category"></p>
                            <p class="item-title"><a href="/hexo/2020/10/27/hello-world/" class="title">Hello World</a></p>
                            <p class="item-date"><time datetime="2020-10-27T05:33:45.370Z" itemprop="datePublished">2020-10-27</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

            
                
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/Java/">Java</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/Spring/">Spring</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/nginx/">nginx</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/springcloud/">springcloud</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F/">镜像加速</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/hexo/categories/%E9%A1%B9%E7%9B%AE/">项目</a><span class="category-list-count">1</span></li></ul>
        </div>
    </div>


            
                
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">归档</h3>
        <div class="widget">
            <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/07/">七月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2021/01/">一月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2020/10/">十月 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2020/06/">六月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2020/05/">五月 2020</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/hexo/archives/2020/04/">四月 2020</a><span class="archive-list-count">3</span></li></ul>
        </div>
    </div>


            
                
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">标签</h3>
        <div class="widget">
            <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/AOP/" rel="tag">AOP</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/Collection/" rel="tag">Collection</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/DI/" rel="tag">DI</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/HashMap/" rel="tag">HashMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/HashTabel/" rel="tag">HashTabel</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/IOC/" rel="tag">IOC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/List/" rel="tag">List</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/Map/" rel="tag">Map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/Set/" rel="tag">Set</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/TreeMap/" rel="tag">TreeMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/idea/" rel="tag">idea</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/jdbc/" rel="tag">jdbc</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/jpa/" rel="tag">jpa</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/mybatis/" rel="tag">mybatis</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/mysql/" rel="tag">mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/npm/" rel="tag">npm</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/orm/" rel="tag">orm</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/properties/" rel="tag">properties</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/thymeleaf/" rel="tag">thymeleaf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/xml/" rel="tag">xml</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/yarn/" rel="tag">yarn</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/%E4%BB%A3%E7%90%86%E6%A8%A1%E5%BC%8F/" rel="tag">代理模式</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/hexo/tags/%E6%B3%9B%E5%9E%8B/" rel="tag">泛型</a><span class="tag-list-count">1</span></li></ul>
        </div>
    </div>


            
                
    <div class="widget-wrap widget-float">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/hexo/tags/AOP/" style="font-size: 10px;">AOP</a> <a href="/hexo/tags/Collection/" style="font-size: 10px;">Collection</a> <a href="/hexo/tags/DI/" style="font-size: 10px;">DI</a> <a href="/hexo/tags/HashMap/" style="font-size: 10px;">HashMap</a> <a href="/hexo/tags/HashTabel/" style="font-size: 10px;">HashTabel</a> <a href="/hexo/tags/IOC/" style="font-size: 10px;">IOC</a> <a href="/hexo/tags/List/" style="font-size: 10px;">List</a> <a href="/hexo/tags/Map/" style="font-size: 10px;">Map</a> <a href="/hexo/tags/Set/" style="font-size: 10px;">Set</a> <a href="/hexo/tags/TreeMap/" style="font-size: 10px;">TreeMap</a> <a href="/hexo/tags/idea/" style="font-size: 20px;">idea</a> <a href="/hexo/tags/jdbc/" style="font-size: 20px;">jdbc</a> <a href="/hexo/tags/jpa/" style="font-size: 10px;">jpa</a> <a href="/hexo/tags/mybatis/" style="font-size: 20px;">mybatis</a> <a href="/hexo/tags/mysql/" style="font-size: 10px;">mysql</a> <a href="/hexo/tags/npm/" style="font-size: 10px;">npm</a> <a href="/hexo/tags/orm/" style="font-size: 10px;">orm</a> <a href="/hexo/tags/properties/" style="font-size: 10px;">properties</a> <a href="/hexo/tags/thymeleaf/" style="font-size: 10px;">thymeleaf</a> <a href="/hexo/tags/xml/" style="font-size: 15px;">xml</a> <a href="/hexo/tags/yarn/" style="font-size: 10px;">yarn</a> <a href="/hexo/tags/%E4%BB%A3%E7%90%86%E6%A8%A1%E5%BC%8F/" style="font-size: 10px;">代理模式</a> <a href="/hexo/tags/%E6%B3%9B%E5%9E%8B/" style="font-size: 10px;">泛型</a>
        </div>
    </div>


            
                
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
                    <li>
                        <a target="_blank" rel="noopener" href="http://hexo.io">Hexo</a>
                    </li>
                
                    <li>
                        <a target="_blank" rel="noopener" href="https://github.com">Github</a>
                    </li>
                
                    <li>
                        <a target="_blank" rel="noopener" href="https://baidu.com">Baidu</a>
                    </li>
                
            </ul>
        </div>
    </div>


            
        
    </div>
</aside>

                </div>
            </div>
        </div>
        <footer id="footer">
    <div class="container">
        <div class="container-inner">
            <a id="back-to-top" href="javascript:;"><i class="icon fa fa-angle-up"></i></a>
            <div class="credit">
                <h1 class="logo-wrap">
                    <a href="/hexo/" class="logo"></a>
                </h1>
                <p>&copy; 2021 XiaoHuang</p>
                
                <p>Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>.</p>
                
            </div>
            <div class="footer-plugins">
              
    


            </div>
        </div>
	</div>
</footer>


    </div>
    
    
    <script>
    var disqus_shortname = 'hexo-theme-hueman';
    
    
    var disqus_url = 'https://hchdream.gitee.io/hexo/2020/05/16/Java%E9%9B%86%E5%90%88%E4%B9%8BMap/';
    
    (function() {
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
    </script>





    
        
<script src="/hexo/libs/lightgallery/js/lightgallery.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-thumbnail.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-pager.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-autoplay.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-fullscreen.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-zoom.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-hash.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-share.min.js"></script>

        
<script src="/hexo/libs/lightgallery/js/lg-video.min.js"></script>

    
    
        
<script src="/hexo/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>

    
    

    
    
    



<!-- Custom Scripts -->

<script src="/hexo/js/main.js"></script>


</body>
</html>
